// index.js
Page({
    data: {
      username:'',
      item: {
        a: false
      },
      images: [
        {
          url: "../../imgs/myhome/chuzhika.png",
          desc: "我的储值卡"
        },
        {
          url: "../../imgs/myhome/youhuijuan.png",
          desc: "我的优惠卷"
        },
        {
          url: "../../imgs/myhome/gouwuche.png",
          desc: "我的购物车"
        }
      ],
      gongneng:[
          {
              url:"../../imgs/myhome/dingdan.png",
              desc:"场馆订单"
          },{
            url:"../../imgs/myhome/shoucang.png",
            desc:"我的收藏"
        },{
            url:"../../imgs/myhome/renwuxinxi.png",
            desc:"出游信息"
        },{
            url:"../../imgs/myhome/shouhuodizhi.png",
            desc:"收货地址"
        }
      ],
      dingdan:[{
          url:"../../imgs/myhome/daifukuan.png",
          desc:"未使用"
      },
      {
          url:"../../imgs/myhome/yiwancheng.png",
          desc:"已完成"
      },{
          url:"../../imgs/myhome/daifahuo.png",
          desc:"待发货"
      },
      {
          url:"../../imgs/myhome/tuikuan.png",
          desc:"已退款"
      }],
      qita:[
          {
              url:"../../imgs/myhome/wodeziliao.png",
              desc:"我的资料"
          },
          {
              url:"../../imgs/myhome/kaipiao.png",
              desc:"开票资料"
          },
          {
              url:"../../imgs/myhome/tianqi.png",
              desc:"天气预报"
          },
          {
            url:"../../imgs/myhome/huancun.png",
            desc:"清理缓存"
        }],
        qita2: [
          {
            url: "../../imgs/myhome/yijian.png",
            desc: "意见反馈",
            active: false
          },
          {
            url: "../../imgs/myhome/xieyi.png",
            desc: "用户协议",
            active: false
          },
          {
            url: "../../imgs/myhome/yinsi.png",
            desc: "隐私条款",
            active: false
          },
          {
            url: "../../imgs/myhome/gengduo.png",
            desc: "关于更多",
            active: false
          }
        ]
    },
    onclick: function(e) {
      const index = e.currentTarget.dataset.index;
      // idx当前索引
      // 遍历更新qita2数组
      const qita2 = this.data.qita2.map((item, idx) => {
        if (idx === index) {
          item.active = true;
        } else {
          item.active = false;
        }
        return item;
      });
      this.setData({
        qita2: qita2
      });
    },
    onShow: function(){
      const username = wx.getStorageSync('username');
      const id = wx.getStorageSync('userId');
      console.log("当前登录用户id = "+id+"当前登陆的用户名"+username);
      this.setData({
        username: username
      });
      if (username) {
        this.setData({
          'item.a': true
        });
      } else {
        this.setData({
          'item.a': false
        });
      }
    },
    handleDingDanTap: function(e) {
      const index = e.currentTarget.dataset.index;
      const desc = this.data.dingdan[index].desc;
      let status = null;
      if (desc === "未使用") {
        status = 0;
      } else if (desc === "已完成") {
        status = 1;
      }
      if (status !== null) {
        wx.setStorageSync('status', status);  
        wx.navigateTo({
          url: `/pages/order/order?status=${status}`,
        });
      }
    }
  });
